﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace PIM_ATE.Electrical
{
    class ClsDataWaveStatus
    {
        public int Id { get; set; }
        public int AllStatusId { get; set; }
        public string ProductSN { get; set; }
        public string Status { get; set; }
        public DateTime Time { get; set; }
        public string Remark1 { get; set; }
        public string Remark2 { get; set; }
        public string Remark3 { get; set; }
    }
    class ClsDataWaveStatusBuilder
    {
        const string TABLE_NAME = "tb_WaveStatus";
        string m_sConnect;
        ClsDataWaveStatus m_WaveStatus;
        bool m_isEnable;

        public ClsDataWaveStatusBuilder(string alias)
        {
            m_sConnect = alias;
            IniFile.SetFileName(System.Windows.Forms.Application.StartupPath + "\\JcDevices.ini");
            m_isEnable = IniFile.IniReadValue("Settings", "IsUploadData", "1") != "0";
        }

        public void construct(ClsDataWaveStatus Status)
        {
            m_WaveStatus = Status;
        }

        public bool updateStatus()
        {
            if (!m_isEnable || GDefine.IS_LOCAL_RESULT_ANTENNA) return true;

            try
            {
                using (var tran = MicroDBHelper.UseTransaction(IsolationLevel.RepeatableRead, m_sConnect))
                {
                    string sValue = "'" + m_WaveStatus.AllStatusId + "','" + m_WaveStatus.ProductSN + "','" + m_WaveStatus.Status + "','" + m_WaveStatus.Time.ToString("yyyy-MM-dd HH:mm:ss.fff") + "'";
                    string sSql = String.Format("insert into {0} ([AllStatusId],[ProductSN],[Status],[Time]) values ({1}) ;", TABLE_NAME, sValue);
                    MicroDBHelper.ExecuteDataTable(sSql, null, m_sConnect);
                    tran.MarkSuccess();
                }
            }
            catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); return false; }
            return true;
        }
    }
}
